<?php

/******************************************************
 *					    LANGUAGES					  *
 ******************************************************/

/**
 * Requires a $language file from a $path
 * @return Array $lang
 * @author Pablo
 * @since 1.0
 */
function blg_get_lang($path=null){
	if(!isset($path))
		$path= blg_get_site_path();
		
	$language= blg_get_config('language');
	$path_to_language= add_trainling_slash($path, DS).'languages'.DS.$language.'.php';
	
	if(is_file($path_to_language)){
		require $path_to_language; //includes a $lang variable
		return $lang;
	}
	
	return FALSE;
}

/**
 * Add language strings to the global language variable $_LANG
 * @param $path
 * @author Pablo
 * @since 1.0
 */
function blg_load_lang($path){
	global $_LANG;
	
	if(FALSE!==($lang= blg_get_lang($path))){
		$_LANG= array_merge($_LANG, $lang);		
		return TRUE;
	}
	
	return FALSE;	
}

/**
 * Get a language string
 * @param $key
 * @param $params
 * @return String
 * @author Pablo
 * @since 1.0
 */
function blg_echo($key, $params= NULL){
	global $_LANG;
	
	if(array_key_exists($key, $_LANG)){
		if(is_array($params)){
			eval('$return = sprintf($_LANG[$key], "'.implode('","', $params).'");');
			return $return;
		}
		else{
			return $_LANG[$key];
		}
	}
	
	return $key;
}

